package com.roncoo.ysq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.ysq.entity.WebsiteLink;
import com.roncoo.ysq.dao.WebsiteLinkMapper;
import com.roncoo.ysq.service.IWebsiteLinkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.junit.platform.commons.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuanshuaiqiang
 * @since 2021-03-23
 */
@Service
public class WebsiteLinkServiceImpl extends ServiceImpl<WebsiteLinkMapper, WebsiteLink> implements IWebsiteLinkService {

    @Resource
    private WebsiteLinkMapper websiteLinkMapper;
    @Override
    public IPage<WebsiteLink> findAll(Page page, WebsiteLink websiteLink) {
        QueryWrapper<WebsiteLink> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(websiteLink.getLinkName())){
            queryWrapper.like("link_name",websiteLink.getLinkName());
        }
        if (websiteLink.getStatusId()!=null){
            queryWrapper.eq("status_id",websiteLink.getStatusId());
        }
        Page page1 = websiteLinkMapper.selectPage(page, queryWrapper);
        return page1;
    }

    /**
     * before 查询数据
     * @return
     */
    @Override
    public List<WebsiteLink> findByStatus() {
        //条件构造器
        QueryWrapper<WebsiteLink> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status_id",0);
        List<WebsiteLink> websiteLinks = websiteLinkMapper.selectList(queryWrapper);
        return websiteLinks;
    }
}
